class MyCircularQueue {

    public int[] elem;
    public int first;
    public int last;

    public MyCircularQueue(int k) {
        elem=new int[k];
    }

    //入队列
    public boolean enQueue(int value) {
        if(isFull()) {
            //满了，直接返回，题目没有让扩容
            return false;
        }
        elem[last]=value;
        last=(last+1)%elem.length;
        return true;
    }

    //出队列
    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }
        first=(first+1)%elem.length;
        return true;
    }

    //得到队头元素
    public int Front() {
        if(isEmpty()) {
            return -1;
        }
        return elem[first];
    }

    //得到队尾元素
    public int Rear() {
        if(isEmpty()) {
            return -1;
        }
        int index=(last==0)?
                elem.length-1:last-1;
        return elem[index];//这样会越界
    }
    
    public boolean isEmpty() {
        return first==last;
    }
    
    public boolean isFull() {
        return (last+1)%elem.length==first;
    }
}